<template>
  <div id="pageWindow" class="seckill">
    <header>
      <img :src="picList[0]">
      <a href="javascript:;" id="share" onclick="share('超级秒杀', '超级秒杀', '');">
        <img src="https://mstatic.shandjj.com/default/common/common-images/share_white.png">
      </a>
    </header>
    <div class="item-module" v-for="(list,index) in picList.slice(1,-2)" :key="index">
      <img :src="list" @click="showMessage">
      <div class="mask" v-if="defaultList!=index"></div>
    </div>
    <div style="height:0.7rem;background:#800205;"></div>
    <div class="info" v-if="!isVip" @click="goTo()">您还不是SVIP会员，去开通&nbsp;&nbsp;>></div>
    <!-- 加载动画 -->
    <loading :show="showLoading" :text="loadingTXT"></loading>
    <div class="loading_box"><div class="load"><div class="circle2"></div><p>闪</p> </div></div>
    <!--返回顶部-->
    <span id="return-top"><img src="https://mstatic.shandjj.com/default/common/common-images/list_numb_press1@2x.png"></span>
  </div>
</template>
<script>
  import { backTop } from 'assets/js/sdjjPublic.js'
  import { resetAddress } from '@/utils/utils.js'
  import BaseUrl from "@/utils/ajaxRequest.js";
  import { Loading } from 'vux'
  export default {
    name:'superSeckill',
    components:{Loading},
    data() {
      return {
        userId:'',
        setLinkString:'',//图片的基本地址
        pageName:'seckill',//图片分类的名称
        defaultList:0,
        picList:[],
        isVip:false,
        loadingTXT:'加载中',
        showLoading:false
      }
    },
    created(){
      this.userId=window.person.user_id;
      this.restTime=window.activityRestTime;//活动开始时间
      this.currentTime=window.currentTime;//当前页面加载获取的时间
      this.formatImgLink();
    },
    mounted(){
      backTop("return-top");
      this.initTime();
      this.checkVip();
    },
    methods: {
      initTime(){
        var dateTime=new Date('2019-03-28T12:00:00').getTime(),limitDay=6;
        var timeStamp=[dateTime];
        for(var i=1;i<limitDay;i++){
          var oneDay=1*24*60*60*1000;//一天的豪秒数
          timeStamp.push(dateTime+oneDay*i)
        };
        var listNum=0;
        var currTime=currentTime*1000; //php返回的秒数*1000转为毫秒数用于js获取当前时间
        for(var j=0;j<timeStamp.length;j++){
          if(currTime<=timeStamp[0]){listNum=0;break;}
          else if(currTime>timeStamp[j] && currTime<timeStamp[j+1]){
            listNum=j;break;
          }else if(currTime>timeStamp[timeStamp.length-1]){
            listNum=timeStamp.length-1;
            break;
          }
        };  
        this.defaultList=listNum;
      },
      checkVip(){
        var _this=this;
        var ajaxt ='?'+new Date().getTime();
        $.post({
          url:`${BaseUrl}/index.php/VipUser/isVipRight`+ajaxt,
          async: false,
          dataType: "json",
          data:{ userId:this.userId},
          success:function(res){
            if(res.code== 200 &&res.status=='success'){ _this.isVip=res.isVip }
            else{console.log(res.message) }
          }
        });
      },
      goTo(){
        var ajaxt = '?t=' + new Date().getTime();
        if(this.userId){ window.location.href= 'sdjj://memberCenter'+ajaxt;}
        else{ nologin(); }
      },
      showMessage() {
        var _this=this;
        if(this.restTime<=0){
          this.$vux.loading.show({text: 'Loading'});
          setTimeout(() => {
            _this.$vux.loading.hide();
            _this.$vux.toast.text('商品已被抢光啦!', 'middle')
          }, 1000);
        }else{
          this.$vux.toast.text('秒杀还未开始!', 'middle');
          setTimeout(() => {
            _this.$vux.loading.hide();
          }, 1000);
        }
      },
      //处理静态资源地址
      formatImgLink(){
        var tempLink=resetAddress();
        if(tempLink.type=='devLine'){
          this.setLinkString=`${tempLink.assetsLink}/default/ActiveImg/celebration/img/`;
        }else if(tempLink.type=='testLine'){
          this.setLinkString=`${tempLink.assetsLink}/default/ActiveImg/celebration/img/`;
        }else if(tempLink.type=='onLine'){
          this.setLinkString=`${tempLink.assetsLink}/default/ActiveImg/celebration/img/`;
        };
        var setLinkString=this.setLinkString;
        this.picList=[
          setLinkString+"pic01.jpg",
          setLinkString+"pic02.jpg",
          setLinkString+"pic03.jpg",
          setLinkString+"pic04.jpg",
          setLinkString+"pic05.jpg",
          setLinkString+"pic06.jpg",
          setLinkString+"pic07.jpg", 
          setLinkString+"pic08.jpg",
          setLinkString+"pic09.jpg"
        ];
      },
    },
  }
</script>

<style >
.seckill {
  width: 100%;
  height: 100%;
  position: relative;
}
#share {
  width: 0.7rem;
  height: 0.7rem;
  padding: 0.15rem 0.3rem;
  position: absolute;
  top: 0.5rem;
  right: 0.2rem;
  box-sizing: content-box;
}
.item-module{position: relative;}
.item-module .mask{
  width:100%;
  height: 100%;
  position: absolute;
  top: 0;left: 0;
  background: rgba(230,204,204,0.3);
}
.info{
  width:100%;
  height: 0.7rem;
  line-height: 0.7rem;
  text-align: center;
  font-size: 0.24rem;
  color: #fff;
  background: #E20718;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 10;
}
</style>